//
//  User.m
//  SDUserDefaultsDemo
//
//  Created by fangyuan ding on 2022/2/17.
//  Copyright © 2022 Dong. All rights reserved.
//

#import "User.h"

@implementation User
#pragma mark - NSCoding
- (instancetype)initWithCoder:(NSCoder *)aDecoder {
    
    if (!(self = [super init])) {
        return nil;
    }
    
    self.userName = [aDecoder decodeObjectForKey:@"userName"];
    
    self.password = [aDecoder decodeObjectForKey:@"password"];
    
    return self;
}
- (id)copyWithZone:(NSZone *)zone{
    User *user = [[User alloc]init];
    user.userName = self.userName;
    user.password = self.password;
    return user;
}

- (void)encodeWithCoder:(NSCoder *)aCoder {
    
    [aCoder encodeObject:self.userName forKey:@"userName"];
    
    [aCoder encodeObject:self.password forKey:@"password"];
    
    
}

- (NSString *)description {
//    if (_userName) {
//        return [NSString stringWithFormat:@"user: %@   password: %@",self.userName,self.password];
//    }
    NSMutableString *str = @"".mutableCopy;
    [str appendString:@"user:{\n"];
    if (self.userName) [str appendFormat:@"  userName:%@,\n", self.userName];
   
    if (self.password) [str appendFormat:@"  service:%@,\n", self.password];
    [str appendString:@"}"];
    return str;
}


@end
